﻿namespace DimensionsHelper.Client.WinUi.Views;

public sealed partial class TaskInformationDetailControl : UserControl
{
    public static readonly DependencyProperty ListDetailsMenuItemProperty = DependencyProperty.Register(
        nameof(ListDetailsMenuItem),
        typeof(IProjectTask),
        typeof(TaskInformationDetailControl),
        new PropertyMetadata(null, OnListDetailsMenuItemPropertyChanged));

    public TaskInformationDetailControl()
    {
        InitializeComponent();
        MessageListView.SizeChanged += (_, _) => ForegroundElement.ChangeView(null, double.MaxValue, null);
    }

    public IProjectTask? ListDetailsMenuItem
    {
        get => GetValue(ListDetailsMenuItemProperty) as IProjectTask;
        set => SetValue(ListDetailsMenuItemProperty, value);
    }

    private static void OnListDetailsMenuItemPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (d is TaskInformationDetailControl control)
        {
            control.ForegroundElement.ChangeView(0, 0, 1);
        }
    }
}